home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / binutils.252 / gas / config / tc-sparc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-12  |  50.3 KB  |  2,413 lines

  1. /* tc-sparc.c -- Assemble for the SPARC
  2.    Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  19.  
  20. #include <stdio.h>
  21. #include <ctype.h>
  22.  
  23. #include "as.h"
  24. #include "subsegs.h"
  25.  
  26. /* careful, this file includes data *declarations* */
  27. #include "opcode/sparc.h"
  28.  
  29. static void sparc_ip PARAMS ((char *));
  30.  
  31. #ifdef sparcv9
  32. static enum sparc_architecture current_architecture = v9;
  33. #else
  34. static enum sparc_architecture current_architecture = v6;
  35. #endif
  36. static int architecture_requested;
  37. static int warn_on_bump;
  38.  
  39. extern int target_big_endian;
  40.  
  41. const relax_typeS md_relax_table[1];
  42.  
  43. /* handle of the OPCODE hash table */
  44. static struct hash_control *op_hash;
  45.  
  46. static void s_data1 PARAMS ((void));
  47. static void s_seg PARAMS ((int));
  48. static void s_proc PARAMS ((int));
  49. static void s_reserve PARAMS ((int));
  50. static void s_common PARAMS ((int));
  51.  
  52. const pseudo_typeS md_pseudo_table[] =
  53. {
  54.   {"align", s_align_bytes, 0},    /* Defaulting is invalid (0) */
  55.   {"common", s_common, 0},
  56.   {"global", s_globl, 0},
  57.   {"half", cons, 2},
  58.   {"optim", s_ignore, 0},
  59.   {"proc", s_proc, 0},
  60.   {"reserve", s_reserve, 0},
  61.   {"seg", s_seg, 0},
  62.   {"skip", s_space, 0},
  63.   {"word", cons, 4},
  64. #ifndef NO_V9
  65.   {"xword", cons, 8},
  66. #ifdef OBJ_ELF
  67.   {"uaxword", cons, 8},
  68. #endif
  69. #endif
  70. #ifdef OBJ_ELF
  71.   /* these are specific to sparc/svr4 */
  72.   {"pushsection", obj_elf_section, 0},
  73.   {"popsection", obj_elf_previous, 0},
  74.   {"uaword", cons, 4},
  75.   {"uahalf", cons, 2},
  76. #endif
  77.   {NULL, 0, 0},
  78. };
  79.  
  80. const int md_short_jump_size = 4;
  81. const int md_long_jump_size = 4;
  82. const int md_reloc_size = 12;    /* Size of relocation record */
  83.  
  84. /* This array holds the chars that always start a comment.  If the
  85.    pre-processor is disabled, these aren't very useful */
  86. const char comment_chars[] = "!";    /* JF removed '|' from comment_chars */
  87.  
  88. /* This array holds the chars that only start a comment at the beginning of
  89.    a line.  If the line seems to have the form '# 123 filename'
  90.    .line and .file directives will appear in the pre-processed output */
  91. /* Note that input_file.c hand checks for '#' at the beginning of the
  92.    first line of the input file.  This is because the compiler outputs
  93.    #NO_APP at the beginning of its output. */
  94. /* Also note that comments started like this one will always
  95.    work if '/' isn't otherwise defined. */
  96. const char line_comment_chars[] = "#";
  97.  
  98. const char line_separator_chars[] = "";
  99.  
  100. /* Chars that can be used to separate mant from exp in floating point nums */
  101. const char EXP_CHARS[] = "eE";
  102.  
  103. /* Chars that mean this number is a floating point constant */
  104. /* As in 0f12.456 */
  105. /* or    0d1.2345e12 */
  106. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  107.  
  108. /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  109.    changed in read.c.  Ideally it shouldn't have to know about it at all,
  110.    but nothing is ideal around here.  */
  111.  
  112. static unsigned char octal[256];
  113. #define isoctal(c)  octal[(unsigned char) (c)]
  114. static unsigned char toHex[256];
  115.  
  116. struct sparc_it
  117.   {
  118.     char *error;
  119.     unsigned long opcode;
  120.     struct nlist *nlistp;
  121.     expressionS exp;
  122.     int pcrel;
  123.     bfd_reloc_code_real_type reloc;
  124.   };
  125.  
  126. struct sparc_it the_insn, set_insn;
  127.  
  128. static INLINE int
  129. in_signed_range (val, max)
  130.      bfd_signed_vma val, max;
  131. {
  132.   if (max <= 0)
  133.     abort ();
  134.   if (val > max)
  135.     return 0;
  136.   if (val < ~max)
  137.     return 0;
  138.   return 1;
  139. }
  140.  
  141. #if 0
  142. static void print_insn PARAMS ((struct sparc_it *insn));
  143. #endif
  144. static int getExpression PARAMS ((char *str));
  145.  
  146. static char *expr_end;
  147. static int special_case;
  148.  
  149. /*
  150.  * Instructions that require wierd handling because they're longer than
  151.  * 4 bytes.
  152.  */
  153. #define    SPECIAL_CASE_SET    1
  154. #define    SPECIAL_CASE_FDIV    2
  155.  
  156. /*
  157.  * sort of like s_lcomm
  158.  *
  159.  */
  160. #ifndef OBJ_ELF
  161. static int max_alignment = 15;
  162. #endif
  163.  
  164. static void
  165. s_reserve (ignore)
  166.      int ignore;
  167. {
  168.   char *name;
  169.   char *p;
  170.   char c;
  171.   int align;
  172.   int size;
  173.   int temp;
  174.   symbolS *symbolP;
  175.  
  176.   name = input_line_pointer;
  177.   c = get_symbol_end ();
  178.   p = input_line_pointer;
  179.   *p = c;
  180.   SKIP_WHITESPACE ();
  181.  
  182.   if (*input_line_pointer != ',')
  183.     {
  184.       as_bad ("Expected comma after name");
  185.       ignore_rest_of_line ();
  186.       return;
  187.     }
  188.  
  189.   ++input_line_pointer;
  190.  
  191.   if ((size = get_absolute_expression ()) < 0)
  192.     {
  193.       as_bad ("BSS length (%d.) <0! Ignored.", size);
  194.       ignore_rest_of_line ();
  195.       return;
  196.     }                /* bad length */
  197.  
  198.   *p = 0;
  199.   symbolP = symbol_find_or_make (name);
  200.   *p = c;
  201.  
  202.   if (strncmp (input_line_pointer, ",\"bss\"", 6) != 0
  203.       && strncmp (input_line_pointer, ",\".bss\"", 7) != 0)
  204.     {
  205.       as_bad ("bad .reserve segment -- expected BSS segment");
  206.       return;
  207.     }
  208.  
  209.   if (input_line_pointer[2] == '.')
  210.     input_line_pointer += 7;
  211.   else
  212.     input_line_pointer += 6;
  213.   SKIP_WHITESPACE ();
  214.  
  215.   if (*input_line_pointer == ',')
  216.     {
  217.       ++input_line_pointer;
  218.  
  219.       SKIP_WHITESPACE ();
  220.       if (*input_line_pointer == '\n')
  221.     {
  222.       as_bad ("Missing alignment");
  223.       return;
  224.     }
  225.  
  226.       align = get_absolute_expression ();
  227. #ifndef OBJ_ELF
  228.       if (align > max_alignment)
  229.     {
  230.       align = max_alignment;
  231.       as_warn ("Alignment too large: %d. assumed.", align);
  232.     }
  233. #endif
  234.       if (align < 0)
  235.     {
  236.       align = 0;
  237.       as_warn ("Alignment negative. 0 assumed.");
  238.     }
  239.  
  240.       record_alignment (bss_section, align);
  241.  
  242.       /* convert to a power of 2 alignment */
  243.       for (temp = 0; (align & 1) == 0; align >>= 1, ++temp);;
  244.  
  245.       if (align != 1)
  246.     {
  247.       as_bad ("Alignment not a power of 2");
  248.       ignore_rest_of_line ();
  249.       return;
  250.     }            /* not a power of two */
  251.  
  252.       align = temp;
  253.     }                /* if has optional alignment */
  254.   else
  255.     align = 0;
  256.  
  257.   if ((S_GET_SEGMENT (symbolP) == bss_section
  258.        || !S_IS_DEFINED (symbolP))
  259. #ifdef OBJ_AOUT
  260.       && S_GET_OTHER (symbolP) == 0
  261.       && S_GET_DESC (symbolP) == 0
  262. #endif
  263.       )
  264.     {
  265.       if (! need_pass_2)
  266.     {
  267.       char *pfrag;
  268.       segT current_seg = now_seg;
  269.       subsegT current_subseg = now_subseg;
  270.  
  271.       subseg_set (bss_section, 1); /* switch to bss */
  272.  
  273.       if (align)
  274.         frag_align (align, 0); /* do alignment */
  275.  
  276.       /* detach from old frag */
  277.       if (S_GET_SEGMENT(symbolP) == bss_section)
  278.         symbolP->sy_frag->fr_symbol = NULL;
  279.  
  280.       symbolP->sy_frag = frag_now;
  281.       pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
  282.                 size, (char *)0);
  283.       *pfrag = 0;
  284.  
  285.       S_SET_SEGMENT (symbolP, bss_section);
  286.  
  287.       subseg_set (current_seg, current_subseg);
  288.     }
  289.     }
  290.   else
  291.     {
  292.       as_warn("Ignoring attempt to re-define symbol %s.", name);
  293.     }                /* if not redefining */
  294.  
  295.   demand_empty_rest_of_line ();
  296. }
  297.  
  298. static void
  299. s_common (ignore)
  300.      int ignore;
  301. {
  302.   char *name;
  303.   char c;
  304.   char *p;
  305.   int temp, size;
  306.   symbolS *symbolP;
  307.  
  308.   name = input_line_pointer;
  309.   c = get_symbol_end ();
  310.   /* just after name is now '\0' */
  311.   p = input_line_pointer;
  312.   *p = c;
  313.   SKIP_WHITESPACE ();
  314.   if (*input_line_pointer != ',')
  315.     {
  316.       as_bad ("Expected comma after symbol-name");
  317.       ignore_rest_of_line ();
  318.       return;
  319.     }
  320.   input_line_pointer++;        /* skip ',' */
  321.   if ((temp = get_absolute_expression ()) < 0)
  322.     {
  323.       as_bad (".COMMon length (%d.) <0! Ignored.", temp);
  324.       ignore_rest_of_line ();
  325.       return;
  326.     }
  327.   size = temp;
  328.   *p = 0;
  329.   symbolP = symbol_find_or_make (name);
  330.   *p = c;
  331.   if (S_IS_DEFINED (symbolP))
  332.     {
  333.       as_bad ("Ignoring attempt to re-define symbol");
  334.       ignore_rest_of_line ();
  335.       return;
  336.     }
  337.   if (S_GET_VALUE (symbolP) != 0)
  338.     {
  339.       if (S_GET_VALUE (symbolP) != size)
  340.     {
  341.       as_warn ("Length of .comm \"%s\" is already %ld. Not changed to %d.",
  342.            S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);
  343.     }
  344.     }
  345.   else
  346.     {
  347. #ifndef OBJ_ELF
  348.       S_SET_VALUE (symbolP, (valueT) size);
  349.       S_SET_EXTERNAL (symbolP);
  350. #endif
  351.     }
  352.   know (symbolP->sy_frag == &zero_address_frag);
  353.   if (*input_line_pointer != ',')
  354.     {
  355.       as_bad ("Expected comma after common length");
  356.       ignore_rest_of_line ();
  357.       return;
  358.     }
  359.   input_line_pointer++;
  360.   SKIP_WHITESPACE ();
  361.   if (*input_line_pointer != '"')
  362.     {
  363.       temp = get_absolute_expression ();
  364. #ifndef OBJ_ELF
  365.       if (temp > max_alignment)
  366.     {
  367.       temp = max_alignment;
  368.       as_warn ("Common alignment too large: %d. assumed", temp);
  369.     }
  370. #endif
  371.       if (temp < 0)
  372.     {
  373.       temp = 0;
  374.       as_warn ("Common alignment negative; 0 assumed");
  375.     }
  376. #ifdef OBJ_ELF
  377.       if (symbolP->local)
  378.     {
  379.       segT old_sec;
  380.       int old_subsec;
  381.       char *p;
  382.       int align;
  383.  
  384.     allocate_bss:
  385.       old_sec = now_seg;
  386.       old_subsec = now_subseg;
  387.       align = temp;
  388.       record_alignment (bss_section, align);
  389.       subseg_set (bss_section, 0);
  390.       if (align)
  391.         frag_align (align, 0);
  392.       if (S_GET_SEGMENT (symbolP) == bss_section)
  393.         symbolP->sy_frag->fr_symbol = 0;
  394.       symbolP->sy_frag = frag_now;
  395.       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
  396.             (char *) 0);
  397.       *p = 0;
  398.       S_SET_SEGMENT (symbolP, bss_section);
  399.       S_CLEAR_EXTERNAL (symbolP);
  400.       subseg_set (old_sec, old_subsec);
  401.     }
  402.       else
  403. #endif
  404.     {
  405.     allocate_common:
  406.       S_SET_VALUE (symbolP, (valueT) size);
  407. #ifdef OBJ_ELF
  408.       S_SET_ALIGN (symbolP, temp);
  409. #endif
  410.       S_SET_EXTERNAL (symbolP);
  411.       /* should be common, but this is how gas does it for now */
  412.       S_SET_SEGMENT (symbolP, bfd_und_section_ptr);
  413.     }
  414.     }
  415.   else
  416.     {
  417.       input_line_pointer++;
  418.       /* @@ Some use the dot, some don't.  Can we get some consistency??  */
  419.       if (*input_line_pointer == '.')
  420.     input_line_pointer++;
  421.       /* @@ Some say data, some say bss.  */
  422.       if (strncmp (input_line_pointer, "bss\"", 4)
  423.       && strncmp (input_line_pointer, "data\"", 5))
  424.     {
  425.       while (*--input_line_pointer != '"')
  426.         ;
  427.       input_line_pointer--;
  428.       goto bad_common_segment;
  429.     }
  430.       while (*input_line_pointer++ != '"')
  431.     ;
  432.       goto allocate_common;
  433.     }
  434.   demand_empty_rest_of_line ();
  435.   return;
  436.  
  437.   {
  438.   bad_common_segment:
  439.     p = input_line_pointer;
  440.     while (*p && *p != '\n')
  441.       p++;
  442.     c = *p;
  443.     *p = '\0';
  444.     as_bad ("bad .common segment %s", input_line_pointer + 1);
  445.     *p = c;
  446.     input_line_pointer = p;
  447.     ignore_rest_of_line ();
  448.     return;
  449.   }
  450. }
  451.  
  452. static void
  453. s_seg (ignore)
  454.      int ignore;
  455. {
  456.  
  457.   if (strncmp (input_line_pointer, "\"text\"", 6) == 0)
  458.     {
  459.       input_line_pointer += 6;
  460.       s_text (0);
  461.       return;
  462.     }
  463.   if (strncmp (input_line_pointer, "\"data\"", 6) == 0)
  464.     {
  465.       input_line_pointer += 6;
  466.       s_data (0);
  467.       return;
  468.     }
  469.   if (strncmp (input_line_pointer, "\"data1\"", 7) == 0)
  470.     {
  471.       input_line_pointer += 7;
  472.       s_data1 ();
  473.       return;
  474.     }
  475.   if (strncmp (input_line_pointer, "\"bss\"", 5) == 0)
  476.     {
  477.       input_line_pointer += 5;
  478.       /* We only support 2 segments -- text and data -- for now, so
  479.      things in the "bss segment" will have to go into data for now.
  480.      You can still allocate SEG_BSS stuff with .lcomm or .reserve. */
  481.       subseg_set (data_section, 255);    /* FIXME-SOMEDAY */
  482.       return;
  483.     }
  484.   as_bad ("Unknown segment type");
  485.   demand_empty_rest_of_line ();
  486. }
  487.  
  488. static void
  489. s_data1 ()
  490. {
  491.   subseg_set (data_section, 1);
  492.   demand_empty_rest_of_line ();
  493. }
  494.  
  495. static void
  496. s_proc (ignore)
  497.      int ignore;
  498. {
  499.   while (!is_end_of_line[(unsigned char) *input_line_pointer])
  500.     {
  501.       ++input_line_pointer;
  502.     }
  503.   ++input_line_pointer;
  504. }
  505.  
  506. #ifndef NO_V9
  507.  
  508. struct priv_reg_entry
  509.   {
  510.     char *name;
  511.     int regnum;
  512.   };
  513.  
  514. struct priv_reg_entry priv_reg_table[] =
  515. {
  516.   {"tpc", 0},
  517.   {"tnpc", 1},
  518.   {"tstate", 2},
  519.   {"tt", 3},
  520.   {"tick", 4},
  521.   {"tba", 5},
  522.   {"pstate", 6},
  523.   {"tl", 7},
  524.   {"pil", 8},
  525.   {"cwp", 9},
  526.   {"cansave", 10},
  527.   {"canrestore", 11},
  528.   {"cleanwin", 12},
  529.   {"otherwin", 13},
  530.   {"wstate", 14},
  531.   {"fq", 15},
  532.   {"ver", 31},
  533.   {"", -1},            /* end marker */
  534. };
  535.  
  536. struct membar_masks
  537. {
  538.   char *name;
  539.   unsigned int len;
  540.   unsigned int mask;
  541. };
  542.  
  543. #define MEMBAR_MASKS_SIZE 7
  544.  
  545. static const struct membar_masks membar_masks[MEMBAR_MASKS_SIZE] =
  546. {
  547.   {"Sync", 4, 0x40},
  548.   {"MemIssue", 8, 0x20},
  549.   {"Lookaside", 9, 0x10},
  550.   {"StoreStore", 10, 0x08},
  551.   {"LoadStore", 9, 0x04},
  552.   {"StoreLoad", 9, 0x02},
  553.   {"LoadLoad", 8, 0x01},
  554. };
  555.  
  556. static int
  557. cmp_reg_entry (p, q)
  558.      struct priv_reg_entry *p, *q;
  559. {
  560.   return strcmp (q->name, p->name);
  561. }
  562.  
  563. #endif
  564.  
  565. /* This function is called once, at assembler startup time.  It should
  566.    set up all the tables, etc. that the MD part of the assembler will need. */
  567. void
  568. md_begin ()
  569. {
  570.   register const char *retval = NULL;
  571.   int lose = 0;
  572.   register unsigned int i = 0;
  573.  
  574.   op_hash = hash_new ();
  575.  
  576.   while (i < NUMOPCODES)
  577.     {
  578.       const char *name = sparc_opcodes[i].name;
  579.       retval = hash_insert (op_hash, name, &sparc_opcodes[i]);
  580.       if (retval != NULL)
  581.     {
  582.       fprintf (stderr, "internal error: can't hash `%s': %s\n",
  583.            sparc_opcodes[i].name, retval);
  584.       lose = 1;
  585.     }
  586.       do
  587.     {
  588.       if (sparc_opcodes[i].match & sparc_opcodes[i].lose)
  589.         {
  590.           fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
  591.                sparc_opcodes[i].name, sparc_opcodes[i].args);
  592.           lose = 1;
  593.         }
  594.       ++i;
  595.     }
  596.       while (i < NUMOPCODES
  597.          && !strcmp (sparc_opcodes[i].name, name));
  598.     }
  599.  
  600.   if (lose)
  601.     as_fatal ("Broken assembler.  No assembly attempted.");
  602.  
  603.   for (i = '0'; i < '8'; ++i)
  604.     octal[i] = 1;
  605.   for (i = '0'; i <= '9'; ++i)
  606.     toHex[i] = i - '0';
  607.   for (i = 'a'; i <= 'f'; ++i)
  608.     toHex[i] = i + 10 - 'a';
  609.   for (i = 'A'; i <= 'F'; ++i)
  610.     toHex[i] = i + 10 - 'A';
  611.  
  612. #ifndef NO_V9
  613.   qsort (priv_reg_table, sizeof (priv_reg_table) / sizeof (priv_reg_table[0]),
  614.      sizeof (priv_reg_table[0]), cmp_reg_entry);
  615. #endif
  616.  
  617.   target_big_endian = 1;
  618. }
  619.  
  620. void
  621. md_assemble (str)
  622.      char *str;
  623. {
  624.   char *toP;
  625.   int rsd;
  626.  
  627.   know (str);
  628.   sparc_ip (str);
  629.  
  630.   /* See if "set" operand is absolute and small; skip sethi if so. */
  631.   if (special_case == SPECIAL_CASE_SET
  632.       && the_insn.exp.X_op == O_constant)
  633.     {
  634.       if (the_insn.exp.X_add_number >= -(1 << 12)
  635.       && the_insn.exp.X_add_number < (1 << 12))
  636.     {
  637.       the_insn.opcode = 0x80102000    /* or %g0,imm,... */
  638.         | (the_insn.opcode & 0x3E000000)    /* dest reg */
  639.         | (the_insn.exp.X_add_number & 0x1FFF);    /* imm */
  640.       special_case = 0;    /* No longer special */
  641.       the_insn.reloc = BFD_RELOC_NONE;    /* No longer relocated */
  642.     }
  643.     }
  644.  
  645.   toP = frag_more (4);
  646.   /* put out the opcode */
  647.   md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
  648.  
  649.   /* put out the symbol-dependent stuff */
  650.   if (the_insn.reloc != BFD_RELOC_NONE)
  651.     {
  652.       fix_new_exp (frag_now,    /* which frag */
  653.            (toP - frag_now->fr_literal),    /* where */
  654.            4,        /* size */
  655.            &the_insn.exp,
  656.            the_insn.pcrel,
  657.            the_insn.reloc);
  658.     }
  659.  
  660.   switch (special_case)
  661.     {
  662.     case SPECIAL_CASE_SET:
  663.       special_case = 0;
  664.       assert (the_insn.reloc == BFD_RELOC_HI22);
  665.       /* See if "set" operand has no low-order bits; skip OR if so. */
  666.       if (the_insn.exp.X_op == O_constant
  667.       && ((the_insn.exp.X_add_number & 0x3FF) == 0))
  668.     return;
  669.       toP = frag_more (4);
  670.       rsd = (the_insn.opcode >> 25) & 0x1f;
  671.       the_insn.opcode = 0x80102000 | (rsd << 25) | (rsd << 14);
  672.       md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
  673.       fix_new_exp (frag_now,    /* which frag */
  674.            (toP - frag_now->fr_literal),    /* where */
  675.            4,        /* size */
  676.            &the_insn.exp,
  677.            the_insn.pcrel,
  678.            BFD_RELOC_LO10);
  679.       return;
  680.  
  681.     case SPECIAL_CASE_FDIV:
  682.       /* According to information leaked from Sun, the "fdiv" instructions
  683.      on early SPARC machines would produce incorrect results sometimes.
  684.      The workaround is to add an fmovs of the destination register to
  685.      itself just after the instruction.  This was true on machines
  686.      with Weitek 1165 float chips, such as the Sun-4/260 and /280. */
  687.       special_case = 0;
  688.       assert (the_insn.reloc == BFD_RELOC_NONE);
  689.       toP = frag_more (4);
  690.       rsd = (the_insn.opcode >> 25) & 0x1f;
  691.       the_insn.opcode = 0x81A00020 | (rsd << 25) | rsd;    /* fmovs dest,dest */
  692.       md_number_to_chars (toP, (valueT) the_insn.opcode, 4);
  693.       return;
  694.  
  695.     case 0:
  696.       return;
  697.  
  698.     default:
  699.       as_fatal ("failed sanity check.");
  700.     }
  701. }
  702.  
  703. /* Implement big shift right.  */
  704. static bfd_vma
  705. BSR (val, amount)
  706.      bfd_vma val;
  707.      int amount;
  708. {
  709.   if (sizeof (bfd_vma) <= 4 && amount >= 32)
  710.     as_fatal ("Support for 64-bit arithmetic not compiled in.");
  711.   return val >> amount;
  712. }
  713.  
  714. static void
  715. sparc_ip (str)
  716.      char *str;
  717. {
  718.   char *error_message = "";
  719.   char *s;
  720.   const char *args;
  721.   char c;
  722.   struct sparc_opcode *insn;
  723.   char *argsStart;
  724.   unsigned long opcode;
  725.   unsigned int mask = 0;
  726.   int match = 0;
  727.   int comma = 0;
  728.   long immediate_max = 0;
  729.  
  730.   for (s = str; islower (*s) || (*s >= '0' && *s <= '3'); ++s)
  731.     ;
  732.   switch (*s)
  733.     {
  734.  
  735.     case '\0':
  736.       break;
  737.  
  738.     case ',':
  739.       comma = 1;
  740.  
  741.       /*FALLTHROUGH */
  742.  
  743.     case ' ':
  744.       *s++ = '\0';
  745.       break;
  746.  
  747.     default:
  748.       as_fatal ("Unknown opcode: `%s'", str);
  749.     }
  750.   if ((insn = (struct sparc_opcode *) hash_find (op_hash, str)) == NULL)
  751.     {
  752.       as_bad ("Unknown opcode: `%s'", str);
  753.       return;
  754.     }
  755.   if (comma)
  756.     {
  757.       *--s = ',';
  758.     }
  759.   argsStart = s;
  760.   for (;;)
  761.     {
  762.       opcode = insn->match;
  763.       memset (&the_insn, '\0', sizeof (the_insn));
  764.       the_insn.reloc = BFD_RELOC_NONE;
  765.  
  766.       /*
  767.        * Build the opcode, checking as we go to make
  768.        * sure that the operands match
  769.        */
  770.       for (args = insn->args;; ++args)
  771.     {
  772.       switch (*args)
  773.         {
  774. #ifndef NO_V9
  775.         case 'K':
  776.           {
  777.         int kmask = 0;
  778.         int i;
  779.  
  780.         /* Parse a series of masks.  */
  781.         if (*s == '#')
  782.           {
  783.             while (*s == '#')
  784.               {
  785.             ++s;
  786.             for (i = 0; i < MEMBAR_MASKS_SIZE; i++)
  787.               if (!strncmp (s, membar_masks[i].name,
  788.                     membar_masks[i].len))
  789.                 break;
  790.             if (i < MEMBAR_MASKS_SIZE)
  791.               {
  792.                 kmask |= membar_masks[i].mask;
  793.                 s += membar_masks[i].len;
  794.               }
  795.             else
  796.               {
  797.                 error_message = ": invalid membar mask name";
  798.                 goto error;
  799.               }
  800.             if (*s == '|')
  801.               ++s;
  802.               }
  803.           }
  804.         else
  805.           {
  806.             expressionS exp;
  807.             char *hold;
  808.             char *send;
  809.  
  810.             hold = input_line_pointer;
  811.             input_line_pointer = s;
  812.             expression (&exp);
  813.             send = input_line_pointer;
  814.             input_line_pointer = hold;
  815.  
  816.             kmask = exp.X_add_number;
  817.             if (exp.X_op != O_constant
  818.             || kmask < 0
  819.             || kmask > 127)
  820.               {
  821.             error_message = ": invalid membar mask number";
  822.             goto error;
  823.               }
  824.  
  825.             s = send;
  826.           }
  827.  
  828.         opcode |= SIMM13 (kmask);
  829.         continue;
  830.           }
  831.  
  832.         case '*':
  833.           {
  834.         int prefetch_fcn = 0;
  835.  
  836.         /* Parse a prefetch function.  */
  837.         if (*s == '#')
  838.           {
  839.             s += 1;
  840.             if (!strncmp (s, "n_reads", 7))
  841.               prefetch_fcn = 0, s += 7;
  842.             else if (!strncmp (s, "one_read", 8))
  843.               prefetch_fcn = 1, s += 8;
  844.             else if (!strncmp (s, "n_writes", 8))
  845.               prefetch_fcn = 2, s += 8;
  846.             else if (!strncmp (s, "one_write", 9))
  847.               prefetch_fcn = 3, s += 9;
  848.             else if (!strncmp (s, "page", 4))
  849.               prefetch_fcn = 4, s += 4;
  850.             else
  851.               {
  852.             error_message = ": invalid prefetch function name";
  853.             goto error;
  854.               }
  855.           }
  856.         else if (isdigit (*s))
  857.           {
  858.             while (isdigit (*s))
  859.               {
  860.             prefetch_fcn = prefetch_fcn * 10 + *s - '0';
  861.             ++s;
  862.               }
  863.  
  864.             if (prefetch_fcn < 0 || prefetch_fcn > 31)
  865.               {
  866.             error_message = ": invalid prefetch function number";
  867.             goto error;
  868.               }
  869.           }
  870.         else
  871.           {
  872.             error_message = ": unrecognizable prefetch function";
  873.             goto error;
  874.           }
  875.         opcode |= RD (prefetch_fcn);
  876.         continue;
  877.           }
  878.  
  879.         case '!':
  880.         case '?':
  881.           /* Parse a privileged register.  */
  882.           if (*s == '%')
  883.         {
  884.           struct priv_reg_entry *p = priv_reg_table;
  885.           unsigned int len = 9999999; /* init to make gcc happy */
  886.  
  887.           s += 1;
  888.           while (p->name[0] > s[0])
  889.             p++;
  890.           while (p->name[0] == s[0])
  891.             {
  892.               len = strlen (p->name);
  893.               if (strncmp (p->name, s, len) == 0)
  894.             break;
  895.               p++;
  896.             }
  897.           if (p->name[0] != s[0])
  898.             {
  899.               error_message = ": unrecognizable privileged register";
  900.               goto error;
  901.             }
  902.           if (*args == '?')
  903.             opcode |= (p->regnum << 14);
  904.           else
  905.             opcode |= (p->regnum << 25);
  906.           s += len;
  907.           continue;
  908.         }
  909.           else
  910.         {
  911.           error_message = ": unrecognizable privileged register";
  912.           goto error;
  913.         }
  914. #endif
  915.  
  916.         case 'M':
  917.         case 'm':
  918.           if (strncmp (s, "%asr", 4) == 0)
  919.         {
  920.           s += 4;
  921.  
  922.           if (isdigit (*s))
  923.             {
  924.               long num = 0;
  925.  
  926.               while (isdigit (*s))
  927.             {
  928.               num = num * 10 + *s - '0';
  929.               ++s;
  930.             }
  931.  
  932.               if (num < 16 || 31 < num)
  933.             {
  934.               error_message = ": asr number must be between 15 and 31";
  935.               goto error;
  936.             }    /* out of range */
  937.  
  938.               opcode |= (*args == 'M' ? RS1 (num) : RD (num));
  939.               continue;
  940.             }
  941.           else
  942.             {
  943.               error_message = ": expecting %asrN";
  944.               goto error;
  945.             }        /* if %asr followed by a number. */
  946.  
  947.         }        /* if %asr */
  948.           break;
  949.  
  950. #ifndef NO_V9
  951.         case 'I':
  952.           the_insn.reloc = BFD_RELOC_SPARC_11;
  953.           immediate_max = 0x03FF;
  954.           goto immediate;
  955.  
  956.         case 'j':
  957.           the_insn.reloc = BFD_RELOC_SPARC_10;
  958.           immediate_max = 0x01FF;
  959.           goto immediate;
  960.  
  961.         case 'k':
  962.           the_insn.reloc = /* RELOC_WDISP2_14 */ BFD_RELOC_SPARC_WDISP16;
  963.           the_insn.pcrel = 1;
  964.           goto immediate;
  965.  
  966.         case 'G':
  967.           the_insn.reloc = BFD_RELOC_SPARC_WDISP19;
  968.           the_insn.pcrel = 1;
  969.           goto immediate;
  970.  
  971.         case 'N':
  972.           if (*s == 'p' && s[1] == 'n')
  973.         {
  974.           s += 2;
  975.           continue;
  976.         }
  977.           break;
  978.  
  979.         case 'T':
  980.           if (*s == 'p' && s[1] == 't')
  981.         {
  982.           s += 2;
  983.           continue;
  984.         }
  985.           break;
  986.  
  987.         case 'z':
  988.           if (*s == ' ')
  989.         {
  990.           ++s;
  991.         }
  992.           if (strncmp (s, "%icc", 4) == 0)
  993.         {
  994.           s += 4;
  995.           continue;
  996.         }
  997.           break;
  998.  
  999.         case 'Z':
  1000.           if (*s == ' ')
  1001.         {
  1002.           ++s;
  1003.         }
  1004.           if (strncmp (s, "%xcc", 4) == 0)
  1005.         {
  1006.           s += 4;
  1007.           continue;
  1008.         }
  1009.           break;
  1010.  
  1011.         case '6':
  1012.           if (*s == ' ')
  1013.         {
  1014.           ++s;
  1015.         }
  1016.           if (strncmp (s, "%fcc0", 5) == 0)
  1017.         {
  1018.           s += 5;
  1019.           continue;
  1020.         }
  1021.           break;
  1022.  
  1023.         case '7':
  1024.           if (*s == ' ')
  1025.         {
  1026.           ++s;
  1027.         }
  1028.           if (strncmp (s, "%fcc1", 5) == 0)
  1029.         {
  1030.           s += 5;
  1031.           continue;
  1032.         }
  1033.           break;
  1034.  
  1035.         case '8':
  1036.           if (*s == ' ')
  1037.         {
  1038.           ++s;
  1039.         }
  1040.           if (strncmp (s, "%fcc2", 5) == 0)
  1041.         {
  1042.           s += 5;
  1043.           continue;
  1044.         }
  1045.           break;
  1046.  
  1047.         case '9':
  1048.           if (*s == ' ')
  1049.         {
  1050.           ++s;
  1051.         }
  1052.           if (strncmp (s, "%fcc3", 5) == 0)
  1053.         {
  1054.           s += 5;
  1055.           continue;
  1056.         }
  1057.           break;
  1058.  
  1059.         case 'P':
  1060.           if (strncmp (s, "%pc", 3) == 0)
  1061.         {
  1062.           s += 3;
  1063.           continue;
  1064.         }
  1065.           break;
  1066.  
  1067.         case 'W':
  1068.           if (strncmp (s, "%tick", 5) == 0)
  1069.         {
  1070.           s += 5;
  1071.           continue;
  1072.         }
  1073.           break;
  1074. #endif /* NO_V9 */
  1075.  
  1076.         case '\0':        /* end of args */
  1077.           if (*s == '\0')
  1078.         {
  1079.           match = 1;
  1080.         }
  1081.           break;
  1082.  
  1083.         case '+':
  1084.           if (*s == '+')
  1085.         {
  1086.           ++s;
  1087.           continue;
  1088.         }
  1089.           if (*s == '-')
  1090.         {
  1091.           continue;
  1092.         }
  1093.           break;
  1094.  
  1095.         case '[':        /* these must match exactly */
  1096.         case ']':
  1097.         case ',':
  1098.         case ' ':
  1099.           if (*s++ == *args)
  1100.         continue;
  1101.           break;
  1102.  
  1103.         case '#':        /* must be at least one digit */
  1104.           if (isdigit (*s++))
  1105.         {
  1106.           while (isdigit (*s))
  1107.             {
  1108.               ++s;
  1109.             }
  1110.           continue;
  1111.         }
  1112.           break;
  1113.  
  1114.         case 'C':        /* coprocessor state register */
  1115.           if (strncmp (s, "%csr", 4) == 0)
  1116.         {
  1117.           s += 4;
  1118.           continue;
  1119.         }
  1120.           break;
  1121.  
  1122.         case 'b':        /* next operand is a coprocessor register */
  1123.         case 'c':
  1124.         case 'D':
  1125.           if (*s++ == '%' && *s++ == 'c' && isdigit (*s))
  1126.         {
  1127.           mask = *s++;
  1128.           if (isdigit (*s))
  1129.             {
  1130.               mask = 10 * (mask - '0') + (*s++ - '0');
  1131.               if (mask >= 32)
  1132.             {
  1133.               break;
  1134.             }
  1135.             }
  1136.           else
  1137.             {
  1138.               mask -= '0';
  1139.             }
  1140.           switch (*args)
  1141.             {
  1142.  
  1143.             case 'b':
  1144.               opcode |= mask << 14;
  1145.               continue;
  1146.  
  1147.             case 'c':
  1148.               opcode |= mask;
  1149.               continue;
  1150.  
  1151.             case 'D':
  1152.               opcode |= mask << 25;
  1153.               continue;
  1154.             }
  1155.         }
  1156.           break;
  1157.  
  1158.         case 'r':        /* next operand must be a register */
  1159.         case '1':
  1160.         case '2':
  1161.         case 'd':
  1162.           if (*s++ == '%')
  1163.         {
  1164.           switch (c = *s++)
  1165.             {
  1166.  
  1167.             case 'f':    /* frame pointer */
  1168.               if (*s++ == 'p')
  1169.             {
  1170.               mask = 0x1e;
  1171.               break;
  1172.             }
  1173.               goto error;
  1174.  
  1175.             case 'g':    /* global register */
  1176.               if (isoctal (c = *s++))
  1177.             {
  1178.               mask = c - '0';
  1179.               break;
  1180.             }
  1181.               goto error;
  1182.  
  1183.             case 'i':    /* in register */
  1184.               if (isoctal (c = *s++))
  1185.             {
  1186.               mask = c - '0' + 24;
  1187.               break;
  1188.             }
  1189.               goto error;
  1190.  
  1191.             case 'l':    /* local register */
  1192.               if (isoctal (c = *s++))
  1193.             {
  1194.               mask = (c - '0' + 16);
  1195.               break;
  1196.             }
  1197.               goto error;
  1198.  
  1199.             case 'o':    /* out register */
  1200.               if (isoctal (c = *s++))
  1201.             {
  1202.               mask = (c - '0' + 8);
  1203.               break;
  1204.             }
  1205.               goto error;
  1206.  
  1207.             case 's':    /* stack pointer */
  1208.               if (*s++ == 'p')
  1209.             {
  1210.               mask = 0xe;
  1211.               break;
  1212.             }
  1213.               goto error;
  1214.  
  1215.             case 'r':    /* any register */
  1216.               if (!isdigit (c = *s++))
  1217.             {
  1218.               goto error;
  1219.             }
  1220.               /* FALLTHROUGH */
  1221.             case '0':
  1222.             case '1':
  1223.             case '2':
  1224.             case '3':
  1225.             case '4':
  1226.             case '5':
  1227.             case '6':
  1228.             case '7':
  1229.             case '8':
  1230.             case '9':
  1231.               if (isdigit (*s))
  1232.             {
  1233.               if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
  1234.                 {
  1235.                   goto error;
  1236.                 }
  1237.             }
  1238.               else
  1239.             {
  1240.               c -= '0';
  1241.             }
  1242.               mask = c;
  1243.               break;
  1244.  
  1245.             default:
  1246.               goto error;
  1247.             }
  1248.           /*
  1249.                      * Got the register, now figure out where
  1250.                      * it goes in the opcode.
  1251.                      */
  1252.           switch (*args)
  1253.             {
  1254.  
  1255.             case '1':
  1256.               opcode |= mask << 14;
  1257.               continue;
  1258.  
  1259.             case '2':
  1260.               opcode |= mask;
  1261.               continue;
  1262.  
  1263.             case 'd':
  1264.               opcode |= mask << 25;
  1265.               continue;
  1266.  
  1267.             case 'r':
  1268.               opcode |= (mask << 25) | (mask << 14);
  1269.               continue;
  1270.             }
  1271.         }
  1272.           break;
  1273.  
  1274.         case 'e':        /* next operand is a floating point register */
  1275.         case 'v':
  1276.         case 'V':
  1277.  
  1278.         case 'f':
  1279.         case 'B':
  1280.         case 'R':
  1281.  
  1282.         case 'g':
  1283.         case 'H':
  1284.         case 'J':
  1285.           {
  1286.         char format;
  1287.  
  1288.         if (*s++ == '%'
  1289.             && ((format = *s) == 'f')
  1290.             && isdigit (*++s))
  1291.           {
  1292.             for (mask = 0; isdigit (*s); ++s)
  1293.               {
  1294.             mask = 10 * mask + (*s - '0');
  1295.               }        /* read the number */
  1296.  
  1297.             if ((*args == 'v'
  1298.              || *args == 'B'
  1299.              || *args == 'H')
  1300.             && (mask & 1))
  1301.               {
  1302.             break;
  1303.               }        /* register must be even numbered */
  1304.  
  1305.             if ((*args == 'V'
  1306.              || *args == 'R'
  1307.              || *args == 'J')
  1308.             && (mask & 3))
  1309.               {
  1310.             break;
  1311.               }        /* register must be multiple of 4 */
  1312.  
  1313. #ifndef NO_V9
  1314.             if (mask >= 64)
  1315.               {
  1316.             error_message = ": There are only 64 f registers; [0-63]";
  1317.             goto error;
  1318.               }    /* on error */
  1319.             if (mask >= 32)
  1320.               {
  1321.             mask -= 31;
  1322.               }    /* wrap high bit */
  1323. #else
  1324.             if (mask >= 32)
  1325.               {
  1326.             error_message = ": There are only 32 f registers; [0-31]";
  1327.             goto error;
  1328.               }    /* on error */
  1329. #endif
  1330.           }
  1331.         else
  1332.           {
  1333.             break;
  1334.           }    /* if not an 'f' register. */
  1335.  
  1336.         switch (*args)
  1337.           {
  1338.  
  1339.           case 'v':
  1340.           case 'V':
  1341.           case 'e':
  1342.             opcode |= RS1 (mask);
  1343.             continue;
  1344.  
  1345.  
  1346.           case 'f':
  1347.           case 'B':
  1348.           case 'R':
  1349.             opcode |= RS2 (mask);
  1350.             continue;
  1351.  
  1352.           case 'g':
  1353.           case 'H':
  1354.           case 'J':
  1355.             opcode |= RD (mask);
  1356.             continue;
  1357.           }        /* pack it in. */
  1358.  
  1359.         know (0);
  1360.         break;
  1361.           }            /* float arg */
  1362.  
  1363.         case 'F':
  1364.           if (strncmp (s, "%fsr", 4) == 0)
  1365.         {
  1366.           s += 4;
  1367.           continue;
  1368.         }
  1369.           break;
  1370.  
  1371.         case 'h':        /* high 22 bits */
  1372.           the_insn.reloc = BFD_RELOC_HI22;
  1373.           goto immediate;
  1374.  
  1375.         case 'l':        /* 22 bit PC relative immediate */
  1376.           the_insn.reloc = BFD_RELOC_SPARC_WDISP22;
  1377.           the_insn.pcrel = 1;
  1378.           goto immediate;
  1379.  
  1380.         case 'L':        /* 30 bit immediate */
  1381.           the_insn.reloc = BFD_RELOC_32_PCREL_S2;
  1382.           the_insn.pcrel = 1;
  1383.           goto immediate;
  1384.  
  1385.         case 'n':        /* 22 bit immediate */
  1386.           the_insn.reloc = BFD_RELOC_SPARC22;
  1387.           goto immediate;
  1388.  
  1389.         case 'i':        /* 13 bit immediate */
  1390.           the_insn.reloc = BFD_RELOC_SPARC13;
  1391.           immediate_max = 0x0FFF;
  1392.  
  1393.           /*FALLTHROUGH */
  1394.  
  1395.         immediate:
  1396.           if (*s == ' ')
  1397.         s++;
  1398.           if (*s == '%')
  1399.         {
  1400.           if ((c = s[1]) == 'h' && s[2] == 'i')
  1401.             {
  1402.               the_insn.reloc = BFD_RELOC_HI22;
  1403.               s += 3;
  1404.             }
  1405.           else if (c == 'l' && s[2] == 'o')
  1406.             {
  1407.               the_insn.reloc = BFD_RELOC_LO10;
  1408.               s += 3;
  1409.             }
  1410. #ifndef NO_V9
  1411.           else if (c == 'u'
  1412.                && s[2] == 'h'
  1413.                && s[3] == 'i')
  1414.             {
  1415.               the_insn.reloc = BFD_RELOC_SPARC_HH22;
  1416.               s += 4;
  1417.             }
  1418.           else if (c == 'u'
  1419.                && s[2] == 'l'
  1420.                && s[3] == 'o')
  1421.             {
  1422.               the_insn.reloc = BFD_RELOC_SPARC_HM10;
  1423.               s += 4;
  1424.             }
  1425. #endif /* NO_V9 */
  1426.           else
  1427.             break;
  1428.         }
  1429.           /* Note that if the getExpression() fails, we will still
  1430.          have created U entries in the symbol table for the
  1431.          'symbols' in the input string.  Try not to create U
  1432.          symbols for registers, etc.  */
  1433.           {
  1434.         /* This stuff checks to see if the expression ends in
  1435.            +%reg.  If it does, it removes the register from
  1436.            the expression, and re-sets 's' to point to the
  1437.            right place.  */
  1438.  
  1439.         char *s1;
  1440.  
  1441.         for (s1 = s; *s1 && *s1 != ',' && *s1 != ']'; s1++);;
  1442.  
  1443.         if (s1 != s && isdigit (s1[-1]))
  1444.           {
  1445.             if (s1[-2] == '%' && s1[-3] == '+')
  1446.               {
  1447.             s1 -= 3;
  1448.             *s1 = '\0';
  1449.             (void) getExpression (s);
  1450.             *s1 = '+';
  1451.             s = s1;
  1452.             continue;
  1453.               }
  1454.             else if (strchr ("goli0123456789", s1[-2]) && s1[-3] == '%' && s1[-4] == '+')
  1455.               {
  1456.             s1 -= 4;
  1457.             *s1 = '\0';
  1458.             (void) getExpression (s);
  1459.             *s1 = '+';
  1460.             s = s1;
  1461.             continue;
  1462.               }
  1463.           }
  1464.           }
  1465.           (void) getExpression (s);
  1466.           s = expr_end;
  1467.  
  1468.           if (the_insn.exp.X_op == O_constant
  1469.           && the_insn.exp.X_add_symbol == 0
  1470.           && the_insn.exp.X_op_symbol == 0)
  1471.         {
  1472. #ifndef NO_V9
  1473.           /* Handle %uhi/%ulo by moving the upper word to the lower
  1474.              one and pretending it's %hi/%lo.  We also need to watch
  1475.              for %hi/%lo: the top word needs to be zeroed otherwise
  1476.              fixup_segment will complain the value is too big.  */
  1477.           switch (the_insn.reloc)
  1478.             {
  1479.             case BFD_RELOC_SPARC_HH22:
  1480.               the_insn.reloc = BFD_RELOC_HI22;
  1481.               the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
  1482.               break;
  1483.             case BFD_RELOC_SPARC_HM10:
  1484.               the_insn.reloc = BFD_RELOC_LO10;
  1485.               the_insn.exp.X_add_number = BSR (the_insn.exp.X_add_number, 32);
  1486.               break;
  1487.             default:
  1488.               break;
  1489.             case BFD_RELOC_HI22:
  1490.             case BFD_RELOC_LO10:
  1491.               the_insn.exp.X_add_number &= 0xffffffff;
  1492.               break;
  1493.             }
  1494. #endif
  1495.           /* For pc-relative call instructions, we reject
  1496.              constants to get better code.  */
  1497.           if (the_insn.pcrel
  1498.               && the_insn.reloc == BFD_RELOC_32_PCREL_S2
  1499.               && in_signed_range (the_insn.exp.X_add_number, 0x3fff)
  1500.               )
  1501.             {
  1502.               error_message = ": PC-relative operand can't be a constant";
  1503.               goto error;
  1504.             }
  1505.           /* Check for invalid constant values.  Don't warn if
  1506.              constant was inside %hi or %lo, since these
  1507.              truncate the constant to fit.  */
  1508.           if (immediate_max != 0
  1509.               && the_insn.reloc != BFD_RELOC_LO10
  1510.               && the_insn.reloc != BFD_RELOC_HI22
  1511.               && !in_signed_range (the_insn.exp.X_add_number,
  1512.                        immediate_max)
  1513.               )
  1514.             {
  1515.               if (the_insn.pcrel)
  1516.             /* Who knows?  After relocation, we may be within
  1517.                range.  Let the linker figure it out.  */
  1518.             {
  1519.               the_insn.exp.X_op = O_symbol;
  1520.               the_insn.exp.X_add_symbol = section_symbol (absolute_section);
  1521.             }
  1522.               else
  1523.             /* Immediate value is non-pcrel, and out of
  1524.                            range.  */
  1525.             as_bad ("constant value %ld out of range (%ld .. %ld)",
  1526.                 the_insn.exp.X_add_number,
  1527.                 ~immediate_max, immediate_max);
  1528.             }
  1529.         }
  1530.  
  1531.           /* Reset to prevent extraneous range check.  */
  1532.           immediate_max = 0;
  1533.  
  1534.           continue;
  1535.  
  1536.         case 'a':
  1537.           if (*s++ == 'a')
  1538.         {
  1539.           opcode |= ANNUL;
  1540.           continue;
  1541.         }
  1542.           break;
  1543.  
  1544.         case 'A':
  1545.           {
  1546. #ifdef NO_V9
  1547.         char *push = input_line_pointer;
  1548.         expressionS e;
  1549.  
  1550.         input_line_pointer = s;
  1551.  
  1552.         expression (&e);
  1553.         if (e.X_op == O_constant)
  1554.           {
  1555.             opcode |= e.X_add_number << 5;
  1556.             s = input_line_pointer;
  1557.             input_line_pointer = push;
  1558.             continue;
  1559.           }        /* if absolute */
  1560.  
  1561.         break;
  1562. #else
  1563.         int asi = 0;
  1564.  
  1565.         /* Parse an asi.  */
  1566.         if (*s == '#')
  1567.           {
  1568.             s += 1;
  1569.             if (!strncmp (s, "ASI_AIUP", 8))
  1570.               asi = 0x10, s += 8;
  1571.             else if (!strncmp (s, "ASI_AIUS", 8))
  1572.               asi = 0x11, s += 8;
  1573.             else if (!strncmp (s, "ASI_PNF", 7))
  1574.               asi = 0x82, s += 7;
  1575.             else if (!strncmp (s, "ASI_SNF", 7))
  1576.               asi = 0x83, s += 7;
  1577.             else if (!strncmp (s, "ASI_P", 5))
  1578.               asi = 0x80, s += 5;
  1579.             else if (!strncmp (s, "ASI_S", 5))
  1580.               asi = 0x81, s += 5;
  1581.             else
  1582.               {
  1583.             error_message = ": invalid asi name";
  1584.             goto error;
  1585.               }
  1586.           }
  1587.         else if (isdigit (*s))
  1588.           {
  1589.             char *push = input_line_pointer;
  1590.             input_line_pointer = s;
  1591.             asi = get_absolute_expression ();
  1592.             s = input_line_pointer;
  1593.             input_line_pointer = push;
  1594.             
  1595.             if (asi < 0 || asi > 255)
  1596.               {
  1597.             error_message = ": invalid asi number";
  1598.             goto error;
  1599.               }
  1600.           }
  1601.         else
  1602.           {
  1603.             error_message = ": unrecognizable asi";
  1604.             goto error;
  1605.           }
  1606.         opcode |= ASI (asi);
  1607.         continue;
  1608. #endif
  1609.           }            /* alternate space */
  1610.  
  1611.         case 'p':
  1612.           if (strncmp (s, "%psr", 4) == 0)
  1613.         {
  1614.           s += 4;
  1615.           continue;
  1616.         }
  1617.           break;
  1618.  
  1619.         case 'q':        /* floating point queue */
  1620.           if (strncmp (s, "%fq", 3) == 0)
  1621.         {
  1622.           s += 3;
  1623.           continue;
  1624.         }
  1625.           break;
  1626.  
  1627.         case 'Q':        /* coprocessor queue */
  1628.           if (strncmp (s, "%cq", 3) == 0)
  1629.         {
  1630.           s += 3;
  1631.           continue;
  1632.         }
  1633.           break;
  1634.  
  1635.         case 'S':
  1636.           if (strcmp (str, "set") == 0)
  1637.         {
  1638.           special_case = SPECIAL_CASE_SET;
  1639.           continue;
  1640.         }
  1641.           else if (strncmp (str, "fdiv", 4) == 0)
  1642.         {
  1643.           special_case = SPECIAL_CASE_FDIV;
  1644.           continue;
  1645.         }
  1646.           break;
  1647.  
  1648. #ifndef NO_V9
  1649.         case 'o':
  1650.           if (strncmp (s, "%asi", 4) != 0)
  1651.         break;
  1652.           s += 4;
  1653.           continue;
  1654.  
  1655.         case 's':
  1656.           if (strncmp (s, "%fprs", 5) != 0)
  1657.         break;
  1658.           s += 5;
  1659.           continue;
  1660.  
  1661.         case 'E':
  1662.           if (strncmp (s, "%ccr", 4) != 0)
  1663.         break;
  1664.           s += 4;
  1665.           continue;
  1666. #endif /* NO_V9 */
  1667.  
  1668.         case 't':
  1669.           if (strncmp (s, "%tbr", 4) != 0)
  1670.         break;
  1671.           s += 4;
  1672.           continue;
  1673.  
  1674.         case 'w':
  1675.           if (strncmp (s, "%wim", 4) != 0)
  1676.         break;
  1677.           s += 4;
  1678.           continue;
  1679.  
  1680. #ifndef NO_V9
  1681.         case 'x':
  1682.           {
  1683.         char *push = input_line_pointer;
  1684.         expressionS e;
  1685.  
  1686.         input_line_pointer = s;
  1687.         expression (&e);
  1688.         if (e.X_op == O_constant)
  1689.           {
  1690.             int n = e.X_add_number;
  1691.             if (n != e.X_add_number || (n & ~0x1ff) != 0)
  1692.               as_bad ("OPF immediate operand out of range (0-0x1ff)");
  1693.             else
  1694.               opcode |= e.X_add_number << 5;
  1695.           }
  1696.         else
  1697.           as_bad ("non-immediate OPF operand, ignored");
  1698.         s = input_line_pointer;
  1699.         input_line_pointer = push;
  1700.         continue;
  1701.           }
  1702. #endif
  1703.  
  1704.         case 'y':
  1705.           if (strncmp (s, "%y", 2) != 0)
  1706.         break;
  1707.           s += 2;
  1708.           continue;
  1709.  
  1710.         default:
  1711.           as_fatal ("failed sanity check.");
  1712.         }            /* switch on arg code */
  1713.       break;
  1714.     }            /* for each arg that we expect */
  1715.     error:
  1716.       if (match == 0)
  1717.     {
  1718.       /* Args don't match. */
  1719.       if (((unsigned) (&insn[1] - sparc_opcodes)) < NUMOPCODES
  1720.           && !strcmp (insn->name, insn[1].name))
  1721.         {
  1722.           ++insn;
  1723.           s = argsStart;
  1724.           continue;
  1725.         }
  1726.       else
  1727.         {
  1728.           as_bad ("Illegal operands%s", error_message);
  1729.           return;
  1730.         }
  1731.     }
  1732.       else
  1733.     {
  1734.       if (insn->architecture > current_architecture
  1735.           || (insn->architecture != current_architecture
  1736.           && current_architecture > v8))
  1737.         {
  1738.           if ((!architecture_requested || warn_on_bump)
  1739.           && !ARCHITECTURES_CONFLICT_P (current_architecture,
  1740.                         insn->architecture)
  1741.           && !ARCHITECTURES_CONFLICT_P (insn->architecture,
  1742.                         current_architecture))
  1743.         {
  1744.           if (warn_on_bump)
  1745.             {
  1746.               as_warn ("architecture bumped from \"%s\" to \"%s\" on \"%s\"",
  1747.                    architecture_pname[current_architecture],
  1748.                    architecture_pname[insn->architecture],
  1749.                    str);
  1750.             }        /* if warning */
  1751.  
  1752.           current_architecture = insn->architecture;
  1753.         }
  1754.           else
  1755.         {
  1756.           as_bad ("Architecture mismatch on \"%s\".", str);
  1757.           as_tsktsk (" (Requires %s; current architecture is %s.)",
  1758.                  architecture_pname[insn->architecture],
  1759.                  architecture_pname[current_architecture]);
  1760.           return;
  1761.         }        /* if bump ok else error */
  1762.         }            /* if architecture higher */
  1763.     }            /* if no match */
  1764.  
  1765.       break;
  1766.     }                /* forever looking for a match */
  1767.  
  1768.   the_insn.opcode = opcode;
  1769. }
  1770.  
  1771. static int
  1772. getExpression (str)
  1773.      char *str;
  1774. {
  1775.   char *save_in;
  1776.   segT seg;
  1777.  
  1778.   save_in = input_line_pointer;
  1779.   input_line_pointer = str;
  1780.   seg = expression (&the_insn.exp);
  1781.   if (seg != absolute_section
  1782.       && seg != text_section
  1783.       && seg != data_section
  1784.       && seg != bss_section
  1785.       && seg != undefined_section)
  1786.     {
  1787.       the_insn.error = "bad segment";
  1788.       expr_end = input_line_pointer;
  1789.       input_line_pointer = save_in;
  1790.       return 1;
  1791.     }
  1792.   expr_end = input_line_pointer;
  1793.   input_line_pointer = save_in;
  1794.   return 0;
  1795. }                /* getExpression() */
  1796.  
  1797.  
  1798. /*
  1799.   This is identical to the md_atof in m68k.c.  I think this is right,
  1800.   but I'm not sure.
  1801.  
  1802.   Turn a string in input_line_pointer into a floating point constant of type
  1803.   type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  1804.   emitted is stored in *sizeP .  An error message is returned, or NULL on OK.
  1805.   */
  1806.  
  1807. /* Equal to MAX_PRECISION in atof-ieee.c */
  1808. #define MAX_LITTLENUMS 6
  1809.  
  1810. char *
  1811. md_atof (type, litP, sizeP)
  1812.      char type;
  1813.      char *litP;
  1814.      int *sizeP;
  1815. {
  1816.   int prec;
  1817.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  1818.   LITTLENUM_TYPE *wordP;
  1819.   char *t;
  1820.   char *atof_ieee ();
  1821.  
  1822.   switch (type)
  1823.     {
  1824.  
  1825.     case 'f':
  1826.     case 'F':
  1827.     case 's':
  1828.     case 'S':
  1829.       prec = 2;
  1830.       break;
  1831.  
  1832.     case 'd':
  1833.     case 'D':
  1834.     case 'r':
  1835.     case 'R':
  1836.       prec = 4;
  1837.       break;
  1838.  
  1839.     case 'x':
  1840.     case 'X':
  1841.       prec = 6;
  1842.       break;
  1843.  
  1844.     case 'p':
  1845.     case 'P':
  1846.       prec = 6;
  1847.       break;
  1848.  
  1849.     default:
  1850.       *sizeP = 0;
  1851.       return "Bad call to MD_ATOF()";
  1852.     }
  1853.   t = atof_ieee (input_line_pointer, type, words);
  1854.   if (t)
  1855.     input_line_pointer = t;
  1856.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  1857.   for (wordP = words; prec--;)
  1858.     {
  1859.       md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
  1860.       litP += sizeof (LITTLENUM_TYPE);
  1861.     }
  1862.   return 0;
  1863. }
  1864.  
  1865. /*
  1866.  * Write out big-endian.
  1867.  */
  1868. void
  1869. md_number_to_chars (buf, val, n)
  1870.      char *buf;
  1871.      valueT val;
  1872.      int n;
  1873. {
  1874.   number_to_chars_bigendian (buf, val, n);
  1875. }
  1876.  
  1877. /* Apply a fixS to the frags, now that we know the value it ought to
  1878.    hold. */
  1879.  
  1880. int
  1881. md_apply_fix (fixP, value)
  1882.      fixS *fixP;
  1883.      valueT *value;
  1884. {
  1885.   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  1886.   offsetT val;
  1887.  
  1888.   val = *value;
  1889.  
  1890.   assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
  1891.  
  1892.   fixP->fx_addnumber = val;    /* Remember value for emit_reloc */
  1893.  
  1894. #ifdef OBJ_ELF
  1895.   /* FIXME: SPARC ELF relocations don't use an addend in the data
  1896.      field itself.  This whole approach should be somehow combined
  1897.      with the calls to bfd_perform_relocation.  */
  1898.   if (fixP->fx_addsy != NULL)
  1899.     return 1;
  1900. #endif
  1901.  
  1902.   /* This is a hack.  There should be a better way to
  1903.      handle this.  Probably in terms of howto fields, once
  1904.      we can look at these fixups in terms of howtos.  */
  1905.   if (fixP->fx_r_type == BFD_RELOC_32_PCREL_S2 && fixP->fx_addsy)
  1906.     val += fixP->fx_where + fixP->fx_frag->fr_address;
  1907.  
  1908. #ifdef OBJ_AOUT
  1909.   /* FIXME: More ridiculous gas reloc hacking.  If we are going to
  1910.      generate a reloc, then we just want to let the reloc addend set
  1911.      the value.  We do not want to also stuff the addend into the
  1912.      object file.  Including the addend in the object file works when
  1913.      doing a static link, because the linker will ignore the object
  1914.      file contents.  However, the dynamic linker does not ignore the
  1915.      object file contents.  */
  1916.   if (fixP->fx_addsy != NULL
  1917.       && fixP->fx_r_type != BFD_RELOC_32_PCREL_S2)
  1918.     val = 0;
  1919. #endif
  1920.  
  1921.   switch (fixP->fx_r_type)
  1922.     {
  1923.     case BFD_RELOC_16:
  1924.       buf[0] = val >> 8;
  1925.       buf[1] = val;
  1926.       break;
  1927.  
  1928.     case BFD_RELOC_32:
  1929.       buf[0] = val >> 24;
  1930.       buf[1] = val >> 16;
  1931.       buf[2] = val >> 8;
  1932.       buf[3] = val;
  1933.       break;
  1934.  
  1935.     case BFD_RELOC_32_PCREL_S2:
  1936.       val = (val >>= 2) + 1;
  1937.       buf[0] |= (val >> 24) & 0x3f;
  1938.       buf[1] = (val >> 16);
  1939.       buf[2] = val >> 8;
  1940.       buf[3] = val;
  1941.       break;
  1942.  
  1943. #ifndef NO_V9
  1944.     case BFD_RELOC_64:
  1945.       {
  1946.     bfd_vma valh = BSR (val, 32);
  1947.     buf[0] = valh >> 24;
  1948.     buf[1] = valh >> 16;
  1949.     buf[2] = valh >> 8;
  1950.     buf[3] = valh;
  1951.     buf[4] = val >> 24;
  1952.     buf[5] = val >> 16;
  1953.     buf[6] = val >> 8;
  1954.     buf[7] = val;
  1955.       }
  1956.       break;
  1957.  
  1958.     case BFD_RELOC_SPARC_11:
  1959.       if (((val > 0) && (val & ~0x7ff))
  1960.       || ((val < 0) && (~(val - 1) & ~0x7ff)))
  1961.     {
  1962.       as_bad ("relocation overflow.");
  1963.     }            /* on overflow */
  1964.  
  1965.       buf[2] |= (val >> 8) & 0x7;
  1966.       buf[3] = val & 0xff;
  1967.       break;
  1968.  
  1969.     case BFD_RELOC_SPARC_10:
  1970.       if (((val > 0) && (val & ~0x3ff))
  1971.       || ((val < 0) && (~(val - 1) & ~0x3ff)))
  1972.     {
  1973.       as_bad ("relocation overflow.");
  1974.     }            /* on overflow */
  1975.  
  1976.       buf[2] |= (val >> 8) & 0x3;
  1977.       buf[3] = val & 0xff;
  1978.       break;
  1979.  
  1980.     case BFD_RELOC_SPARC_WDISP16:
  1981.       if (((val > 0) && (val & ~0x3fffc))
  1982.       || ((val < 0) && (~(val - 1) & ~0x3fffc)))
  1983.     {
  1984.       as_bad ("relocation overflow.");
  1985.     }            /* on overflow */
  1986.  
  1987.       val = (val >>= 2) + 1;
  1988.       buf[1] |= ((val >> 14) & 0x3) << 4;
  1989.       buf[2] |= (val >> 8) & 0x3f;
  1990.       buf[3] = val & 0xff;
  1991.       break;
  1992.  
  1993.     case BFD_RELOC_SPARC_WDISP19:
  1994.       if (((val > 0) && (val & ~0x1ffffc))
  1995.       || ((val < 0) && (~(val - 1) & ~0x1ffffc)))
  1996.     {
  1997.       as_bad ("relocation overflow.");
  1998.     }            /* on overflow */
  1999.  
  2000.       val = (val >>= 2) + 1;
  2001.       buf[1] |= (val >> 16) & 0x7;
  2002.       buf[2] = (val >> 8) & 0xff;
  2003.       buf[3] = val & 0xff;
  2004.       break;
  2005.  
  2006.     case BFD_RELOC_SPARC_HH22:
  2007.       val = BSR (val, 32);
  2008.       /* intentional fallthrough */
  2009. #endif /* NO_V9 */
  2010.  
  2011. #ifndef NO_V9
  2012.     case BFD_RELOC_SPARC_LM22:
  2013. #endif
  2014.     case BFD_RELOC_HI22:
  2015.       if (!fixP->fx_addsy)
  2016.     {
  2017.       buf[1] |= (val >> 26) & 0x3f;
  2018.       buf[2] = val >> 18;
  2019.       buf[3] = val >> 10;
  2020.     }
  2021.       else
  2022.     {
  2023.       buf[2] = 0;
  2024.       buf[3] = 0;
  2025.     }
  2026.       break;
  2027.  
  2028.     case BFD_RELOC_SPARC22:
  2029.       if (val & ~0x003fffff)
  2030.     {
  2031.       as_bad ("relocation overflow");
  2032.     }            /* on overflow */
  2033.       buf[1] |= (val >> 16) & 0x3f;
  2034.       buf[2] = val >> 8;
  2035.       buf[3] = val & 0xff;
  2036.       break;
  2037.  
  2038. #ifndef NO_V9
  2039.     case BFD_RELOC_SPARC_HM10:
  2040.       val = BSR (val, 32);
  2041.       /* intentional fallthrough */
  2042. #endif /* NO_V9 */
  2043.  
  2044.     case BFD_RELOC_LO10:
  2045.       if (!fixP->fx_addsy)
  2046.     {
  2047.       buf[2] |= (val >> 8) & 0x03;
  2048.       buf[3] = val;
  2049.     }
  2050.       else
  2051.     buf[3] = 0;
  2052.       break;
  2053.  
  2054.     case BFD_RELOC_SPARC13:
  2055.       if (! in_signed_range (val, 0x1fff))
  2056.     as_bad ("relocation overflow");
  2057.  
  2058.       buf[2] |= (val >> 8) & 0x1f;
  2059.       buf[3] = val;
  2060.       break;
  2061.  
  2062.     case BFD_RELOC_SPARC_WDISP22:
  2063.       val = (val >> 2) + 1;
  2064.       /* FALLTHROUGH */
  2065.     case BFD_RELOC_SPARC_BASE22:
  2066.       buf[1] |= (val >> 16) & 0x3f;
  2067.       buf[2] = val >> 8;
  2068.       buf[3] = val;
  2069.       break;
  2070.  
  2071.     case BFD_RELOC_NONE:
  2072.     default:
  2073.       as_bad ("bad or unhandled relocation type: 0x%02x", fixP->fx_r_type);
  2074.       break;
  2075.     }
  2076.  
  2077.   /* Are we finished with this relocation now?  */
  2078.   if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
  2079.     fixP->fx_done = 1;
  2080.  
  2081.   return 1;
  2082. }
  2083.  
  2084. /* Translate internal representation of relocation info to BFD target
  2085.    format.  */
  2086. arelent *
  2087. tc_gen_reloc (section, fixp)
  2088.      asection *section;
  2089.      fixS *fixp;
  2090. {
  2091.   arelent *reloc;
  2092.   bfd_reloc_code_real_type code;
  2093.  
  2094.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  2095.   assert (reloc != 0);
  2096.  
  2097.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2098.   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2099.  
  2100.   switch (fixp->fx_r_type)
  2101.     {
  2102.     case BFD_RELOC_16:
  2103.     case BFD_RELOC_32:
  2104.     case BFD_RELOC_HI22:
  2105.     case BFD_RELOC_LO10:
  2106.     case BFD_RELOC_32_PCREL_S2:
  2107.     case BFD_RELOC_SPARC13:
  2108.     case BFD_RELOC_SPARC_BASE13:
  2109.     case BFD_RELOC_SPARC_WDISP22:
  2110.     case BFD_RELOC_64:
  2111.     case BFD_RELOC_SPARC_10:
  2112.     case BFD_RELOC_SPARC_11:
  2113.     case BFD_RELOC_SPARC_HH22:
  2114.     case BFD_RELOC_SPARC_HM10:
  2115.     case BFD_RELOC_SPARC_LM22:
  2116.     case BFD_RELOC_SPARC_PC_HH22:
  2117.     case BFD_RELOC_SPARC_PC_HM10:
  2118.     case BFD_RELOC_SPARC_PC_LM22:
  2119.       code = fixp->fx_r_type;
  2120.       break;
  2121.     default:
  2122.       abort ();
  2123.     }
  2124.   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  2125.   if (reloc->howto == 0)
  2126.     {
  2127.       as_bad_where (fixp->fx_file, fixp->fx_line,
  2128.             "internal error: can't export reloc type %d (`%s')",
  2129.             fixp->fx_r_type, bfd_get_reloc_code_name (code));
  2130.       return 0;
  2131.     }
  2132.   assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
  2133.  
  2134.   /* @@ Why fx_addnumber sometimes and fx_offset other times?  */
  2135. #ifdef OBJ_AOUT
  2136.  
  2137.   if (reloc->howto->pc_relative == 0)
  2138.     reloc->addend = fixp->fx_addnumber;
  2139.   else
  2140.     reloc->addend = fixp->fx_offset - reloc->address;
  2141.  
  2142. #else /* elf or coff */
  2143.  
  2144.   if (reloc->howto->pc_relative == 0)
  2145.     reloc->addend = fixp->fx_addnumber;
  2146.   else if ((fixp->fx_addsy->bsym->flags & BSF_SECTION_SYM) != 0)
  2147.     reloc->addend = (section->vma
  2148.              + fixp->fx_addnumber
  2149.              + md_pcrel_from (fixp));
  2150.   else
  2151.     reloc->addend = fixp->fx_offset;
  2152.  
  2153. #endif
  2154.  
  2155.   return reloc;
  2156. }
  2157.  
  2158.  
  2159. #if 0
  2160. /* for debugging only */
  2161. static void
  2162. print_insn (insn)
  2163.      struct sparc_it *insn;
  2164. {
  2165.   const char *const Reloc[] = {
  2166.     "RELOC_8",
  2167.     "RELOC_16",
  2168.     "RELOC_32",
  2169.     "RELOC_DISP8",
  2170.     "RELOC_DISP16",
  2171.     "RELOC_DISP32",
  2172.     "RELOC_WDISP30",
  2173.     "RELOC_WDISP22",
  2174.     "RELOC_HI22",
  2175.     "RELOC_22",
  2176.     "RELOC_13",
  2177.     "RELOC_LO10",
  2178.     "RELOC_SFA_BASE",
  2179.     "RELOC_SFA_OFF13",
  2180.     "RELOC_BASE10",
  2181.     "RELOC_BASE13",
  2182.     "RELOC_BASE22",
  2183.     "RELOC_PC10",
  2184.     "RELOC_PC22",
  2185.     "RELOC_JMP_TBL",
  2186.     "RELOC_SEGOFF16",
  2187.     "RELOC_GLOB_DAT",
  2188.     "RELOC_JMP_SLOT",
  2189.     "RELOC_RELATIVE",
  2190.     "NO_RELOC"
  2191.   };
  2192.  
  2193.   if (insn->error)
  2194.     fprintf (stderr, "ERROR: %s\n");
  2195.   fprintf (stderr, "opcode=0x%08x\n", insn->opcode);
  2196.   fprintf (stderr, "reloc = %s\n", Reloc[insn->reloc]);
  2197.   fprintf (stderr, "exp = {\n");
  2198.   fprintf (stderr, "\t\tX_add_symbol = %s\n",
  2199.        ((insn->exp.X_add_symbol != NULL)
  2200.         ? ((S_GET_NAME (insn->exp.X_add_symbol) != NULL)
  2201.            ? S_GET_NAME (insn->exp.X_add_symbol)
  2202.            : "???")
  2203.         : "0"));
  2204.   fprintf (stderr, "\t\tX_sub_symbol = %s\n",
  2205.        ((insn->exp.X_op_symbol != NULL)
  2206.         ? (S_GET_NAME (insn->exp.X_op_symbol)
  2207.            ? S_GET_NAME (insn->exp.X_op_symbol)
  2208.            : "???")
  2209.         : "0"));
  2210.   fprintf (stderr, "\t\tX_add_number = %d\n",
  2211.        insn->exp.X_add_number);
  2212.   fprintf (stderr, "}\n");
  2213. }
  2214. #endif
  2215.  
  2216. /*
  2217.  * md_parse_option
  2218.  *    Invocation line includes a switch not recognized by the base assembler.
  2219.  *    See if it's a processor-specific option.  These are:
  2220.  *
  2221.  *    -bump
  2222.  *        Warn on architecture bumps.  See also -A.
  2223.  *
  2224.  *    -Av6, -Av7, -Av8, -Av9, -Asparclite
  2225.  *        Select the architecture.  Instructions or features not
  2226.  *        supported by the selected architecture cause fatal errors.
  2227.  *
  2228.  *        The default is to start at v6, and bump the architecture up
  2229.  *        whenever an instruction is seen at a higher level.
  2230.  *
  2231.  *        If -bump is specified, a warning is printing when bumping to
  2232.  *        higher levels.
  2233.  *
  2234.  *        If an architecture is specified, all instructions must match
  2235.  *        that architecture.  Any higher level instructions are flagged
  2236.  *        as errors.
  2237.  *
  2238.  *        if both an architecture and -bump are specified, the
  2239.  *        architecture starts at the specified level, but bumps are
  2240.  *        warnings.
  2241.  *
  2242.  * Note:
  2243.  *        Bumping between incompatible architectures is always an
  2244.  *        error.  For example, from sparclite to v9.
  2245.  */
  2246.  
  2247. #ifdef OBJ_ELF
  2248. CONST char *md_shortopts = "A:VQ:sq";
  2249. #else
  2250. CONST char *md_shortopts = "A:";
  2251. #endif
  2252. struct option md_longopts[] = {
  2253. #define OPTION_BUMP (OPTION_MD_BASE)
  2254.   {"bump", no_argument, NULL, OPTION_BUMP},
  2255. #define OPTION_SPARC (OPTION_MD_BASE + 1)
  2256.   {"sparc", no_argument, NULL, OPTION_SPARC},
  2257.   {NULL, no_argument, NULL, 0}
  2258. };
  2259. size_t md_longopts_size = sizeof(md_longopts);
  2260.  
  2261. int
  2262. md_parse_option (c, arg)
  2263.      int c;
  2264.      char *arg;
  2265. {
  2266.   switch (c)
  2267.     {
  2268.     case OPTION_BUMP:
  2269.       warn_on_bump = 1;
  2270.       break;
  2271.  
  2272.     case 'A':
  2273.       {
  2274.     char *p = arg;
  2275.     const char **arch;
  2276.  
  2277.     for (arch = architecture_pname; *arch != NULL; ++arch)
  2278.       {
  2279.         if (strcmp (p, *arch) == 0)
  2280.           break;
  2281.       }
  2282.  
  2283.     if (*arch == NULL)
  2284.       {
  2285.         as_bad ("invalid architecture -A%s", p);
  2286.         return 0;
  2287.       }
  2288.     else
  2289.       {
  2290.         enum sparc_architecture new_arch = arch - architecture_pname;
  2291. #ifdef NO_V9
  2292.         if (new_arch == v9)
  2293.           {
  2294.         as_error ("v9 support not compiled in");
  2295.         return 0;
  2296.           }
  2297. #endif
  2298.         current_architecture = new_arch;
  2299.         architecture_requested = 1;
  2300.       }
  2301.       }
  2302.       break;
  2303.  
  2304.     case OPTION_SPARC:
  2305.       /* Ignore -sparc, used by SunOS make default .s.o rule.  */
  2306.       break;
  2307.  
  2308. #ifdef OBJ_ELF
  2309.     case 'V':
  2310.       print_version_id ();
  2311.       break;
  2312.  
  2313.     case 'Q':
  2314.       /* Qy - do emit .comment
  2315.      Qn - do not emit .comment */
  2316.       break;
  2317.  
  2318.     case 's':
  2319.       /* use .stab instead of .stab.excl */
  2320.       break;
  2321.  
  2322.     case 'q':
  2323.       /* quick -- native assembler does fewer checks */
  2324.       break;
  2325. #endif
  2326.  
  2327.     default:
  2328.       return 0;
  2329.     }
  2330.  
  2331.  return 1;
  2332. }
  2333.  
  2334. void
  2335. md_show_usage (stream)
  2336.      FILE *stream;
  2337. {
  2338.   const char **arch;
  2339.   fprintf(stream, "SPARC options:\n");
  2340.   for (arch = architecture_pname; *arch; arch++)
  2341.     {
  2342.       if (arch != architecture_pname)
  2343.     fprintf (stream, " | ");
  2344.       fprintf (stream, "-A%s", *arch);
  2345.     }
  2346.   fprintf (stream, "\n\
  2347.             specify variant of SPARC architecture\n\
  2348. -bump            warn when assembler switches architectures\n\
  2349. -sparc            ignored\n");
  2350. #ifdef OBJ_ELF
  2351.   fprintf(stream, "\
  2352. -V            print assembler version number\n\
  2353. -q            ignored\n\
  2354. -Qy, -Qn        ignored\n\
  2355. -s            ignored\n");
  2356. #endif
  2357. }
  2358.  
  2359. /* We have no need to default values of symbols. */
  2360.  
  2361. /* ARGSUSED */
  2362. symbolS *
  2363. md_undefined_symbol (name)
  2364.      char *name;
  2365. {
  2366.   return 0;
  2367. }                /* md_undefined_symbol() */
  2368.  
  2369. /* Parse an operand that is machine-specific.
  2370.    We just return without modifying the expression if we have nothing
  2371.    to do. */
  2372.  
  2373. /* ARGSUSED */
  2374. void 
  2375. md_operand (expressionP)
  2376.      expressionS *expressionP;
  2377. {
  2378. }
  2379.  
  2380. /* Round up a section size to the appropriate boundary. */
  2381. valueT
  2382. md_section_align (segment, size)
  2383.      segT segment;
  2384.      valueT size;
  2385. {
  2386. #ifndef OBJ_ELF
  2387.   /* This is not right for ELF; a.out wants it, and COFF will force
  2388.      the alignment anyways.  */
  2389.   valueT align = ((valueT) 1
  2390.           << (valueT) bfd_get_section_alignment (stdoutput, segment));
  2391.   valueT newsize;
  2392.   /* turn alignment value into a mask */
  2393.   align--;
  2394.   newsize = (size + align) & ~align;
  2395.   return newsize;
  2396. #else
  2397.   return size;
  2398. #endif
  2399. }
  2400.  
  2401. /* Exactly what point is a PC-relative offset relative TO?
  2402.    On the sparc, they're relative to the address of the offset, plus
  2403.    its size.  This gets us to the following instruction.
  2404.    (??? Is this right?  FIXME-SOON) */
  2405. long 
  2406. md_pcrel_from (fixP)
  2407.      fixS *fixP;
  2408. {
  2409.   return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
  2410. }
  2411.  
  2412. /* end of tc-sparc.c */
  2413.